package cn.com.inossem.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.Date;

/**
 * Created by Mickey.Li on 2017-9-5.
 */
public class HourApplyBean implements Parcelable {
	public ExpenseApplyBean.Project project;
	public String no;
	public String approveMail;
	public int sumHours;
	public double preIncome;
	public ArrayList<HourItemBean> items = new ArrayList<>();
	public Date createDate;
	public Date updateDate;
	public ProjectBean projectInfoUser = new ProjectBean();
	public String id;

	public void setProjectId(String id) {
		project = new ExpenseApplyBean.Project(id);
	}

	public static class HourItemBean implements Parcelable {
		public String id;
		public String datStr;
		public int hours;
		public Date dat;

		@Override
		public int describeContents() {
			return 0;
		}

		@Override
		public void writeToParcel(Parcel dest, int flags) {
			dest.writeString(this.id);
			dest.writeString(this.datStr);
			dest.writeInt(this.hours);
			dest.writeLong(this.dat != null ? this.dat.getTime() : -1);
		}

		public HourItemBean() {
		}

		HourItemBean(Parcel in) {
			this.id = in.readString();
			this.datStr = in.readString();
			this.hours = in.readInt();
			long tmpDat = in.readLong();
			this.dat = tmpDat == -1 ? null : new Date(tmpDat);
		}

		public static final Creator<HourItemBean> CREATOR = new Creator<HourItemBean>() {
			@Override
			public HourItemBean createFromParcel(Parcel source) {
				return new HourItemBean(source);
			}

			@Override
			public HourItemBean[] newArray(int size) {
				return new HourItemBean[size];
			}
		};
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeParcelable(this.project, flags);
		dest.writeString(this.no);
		dest.writeString(this.approveMail);
		dest.writeInt(this.sumHours);
		dest.writeDouble(this.preIncome);
		dest.writeTypedList(this.items);
		dest.writeLong(this.createDate != null ? this.createDate.getTime() : -1);
		dest.writeLong(this.updateDate != null ? this.updateDate.getTime() : -1);
		dest.writeParcelable(this.projectInfoUser, flags);
		dest.writeString(this.id);
	}

	public HourApplyBean() {
	}

	protected HourApplyBean(Parcel in) {
		this.project = in.readParcelable(ExpenseApplyBean.Project.class.getClassLoader());
		this.no = in.readString();
		this.approveMail = in.readString();
		this.sumHours = in.readInt();
		this.preIncome = in.readDouble();
		this.items = in.createTypedArrayList(HourItemBean.CREATOR);
		long tmpCreateDate = in.readLong();
		this.createDate = tmpCreateDate == -1 ? null : new Date(tmpCreateDate);
		long tmpUpdateDate = in.readLong();
		this.updateDate = tmpUpdateDate == -1 ? null : new Date(tmpUpdateDate);
		this.projectInfoUser = in.readParcelable(ProjectBean.class.getClassLoader());
		this.id = in.readString();
	}

	public static final Creator<HourApplyBean> CREATOR = new Creator<HourApplyBean>() {
		@Override
		public HourApplyBean createFromParcel(Parcel source) {
			return new HourApplyBean(source);
		}

		@Override
		public HourApplyBean[] newArray(int size) {
			return new HourApplyBean[size];
		}
	};
}